#
# Makefile for sash
#
# The HAVE_GZIP definition adds the -gzip and -gunzip commands.
# The HAVE_LINUX_ATTR definition adds the -chattr and -lsattr commands.
# The HAVE_LINUX_MOUNT definition makes -mount and -umount work on Linux.
# The HAVE_BSD_MOUNT definition makes -mount and -umount work on BSD.
# The MOUNT_TYPE definition sets the default file system type for -mount.
#
HAVE_GZIP		= 0
HAVE_LINUX_ATTR		= 0
HAVE_LINUX_MOUNT	= 0
HAVE_BSD_MOUNT		= 0
MOUNT_TYPE		= '"ext3"'

CC=gcc
CFLAGS = -g -Wmissing-prototypes \
	-DHAVE_GZIP=$(HAVE_GZIP) \
	-DHAVE_LINUX_ATTR=$(HAVE_LINUX_ATTR) \
	-DHAVE_LINUX_MOUNT=$(HAVE_LINUX_MOUNT) \
	-DHAVE_BSD_MOUNT=$(HAVE_BSD_MOUNT) \
	-DMOUNT_TYPE=$(MOUNT_TYPE)

#LDFLAGS = -static -s
LIBS = -ll -lm -lfl #-lz


BINDIR = /bin
MANDIR = /usr/man/man1


OBJS = sash.o cmds.o cmd_dd.o cmd_ed.o cmd_grep.o cmd_ls.o cmd_tar.o \
	cmd_gzip.o cmd_find.o cmd_file.o cmd_chattr.o cmd_ar.o utils.o eval-upmc.o parser.lex.o parser.y.o

all: sash

sash:	$(OBJS) create-parser
	$(CC) $(LDFLAGS) -o sash $(OBJS) $(LIBS)

eval-upmc:
	make clean
	bison -d parser.y
	mv parser.tab.h parser.h
	mv parser.tab.c parser.y.c
	flex lex.yy
	mv lex.yy.c parser.lex.c
	gcc -o parser.lex.o -c parser.lex.c
	gcc -c parser.y.c -o parser.y.o
	gcc -g -o eval-upmc eval-upmc.c parser.lex.o parser.y.o eval-upmc.h -ll -lm -lfl

create-parser:
	bison -d parser.y
	mv parser.tab.h parser.h
	mv parser.tab.c parser.y.c
	flex lex.yy
	mv lex.yy.c parser.lex.c
	gcc -o parser.lex.o -c parser.lex.c
	gcc -c parser.y.c -o parser.y.o

clean:
	rm -f $(OBJS) sash eval-upmc parser.h parser.y.c parser.lex.c parser.lex.o parser.y.o parser

install: sash
	cp sash $(BINDIR)/sash
	cp sash.1 $(MANDIR)/sash.1

$(OBJS): sash.h eval-upmc.h



.PHONY: create-parser eval-upmc